package org.bees.cms.core.content;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EntityListeners;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;

import org.bees.cms.core.util.validation.Validatable;
import org.bees.cms.core.util.validation.Validator;

@Entity
@EntityListeners(value = { Validator.class })
public class Article extends Content implements Validatable {
	private static final long serialVersionUID = -2190406163738393783L;

	private String title;
	private String author;
	private String body;
	private Topic topic;
	private Category category;

	@Column(length = 24, nullable = false)
	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	@Column(length = 24)
	public String getAuthor() {
		return author;
	}

	public void setAuthor(String author) {
		this.author = author;
	}

	@Lob
	public String getBody() {
		return body;
	}

	public void setBody(String body) {
		this.body = body;
	}

	@ManyToOne(cascade = { CascadeType.REFRESH })
	public Topic getTopic() {
		return topic;
	}

	public void setTopic(Topic topic) {
		this.topic = topic;
	}

	@ManyToOne(cascade = { CascadeType.REFRESH })
	public Category getCategory() {
		return category;
	}

	public void setCategory(Category category) {
		this.category = category;
	}

	@Override
	public boolean validate() {
		return topic != null || category != null;
	}

}
